package com.fs.niukewang.huawei;

import java.util.*;


/**
 * 合并表记录,先输入键值对的个数
 * 然后输入成对的index和value值，以空格隔开
 * 4
 * 0 1
 * 0 2
 * 1 2
 * 3 4
 *
 * 0 3
 * 1 2
 * 3 4
 *
 * Author  hyq
 * 2020/12/30
 */
public class hebingshuju {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            int n = sc.nextInt();
            Map<Integer,Integer> map = new TreeMap<>();
            for(int i=0;i<n;i++){
                int key = sc.nextInt();
                int value = sc.nextInt();
                if (map.containsKey(key)){
                    map.put(key,map.get(key)+value);
                }else {
                    map.put(key,value);
                }

            }

            for (Integer key:map.keySet()){
                System.out.println(key+" "+map.get(key));
            }
        }
    }
}
